/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ejb.otherUtil;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 *
 * @author jackie
 */
public class DigestByMD5 {
    public DigestByMD5(){}
    
    public String stringToMD5(String str) throws NoSuchAlgorithmException{
    
            String reStr = null;  
            MessageDigest md5 = MessageDigest.getInstance("MD5");  
            byte[] bytes = md5.digest(str.getBytes());  
            StringBuilder stringBuffer = new StringBuilder();  
            for (byte b : bytes){  
                int bt = b&0xff;  
                if (bt < 16){  
                    stringBuffer.append(0);  
                }   
                stringBuffer.append(Integer.toHexString(bt));  
            }  
            reStr = stringBuffer.toString();  
   
        return reStr;          
    }
    
    public static void main(String[] args) throws NoSuchAlgorithmException{
        String temp = "33";
        String temp1;
        DigestByMD5 MD5 = new DigestByMD5();
        temp1 = MD5.stringToMD5(temp);
        System.out.println(temp+" : "+temp1); 

        
    }
        
}